package com.eascs.web.o2o.report.service;

import java.util.Date;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.eascs.app.log.Logger;
import com.eascs.app.log.LoggerFactory;
import com.eascs.site.view.HtmlRestResult;
import com.eascs.site.view.ViewContext;
import com.eascs.web.o2o.report.dao.O2OMessageDao;

@Service
public class MessageEmailServiceImpl {
	private static Logger log = LoggerFactory.getLogger(MessageEmailServiceImpl.class);

	@Value("${msg.message.receivers}")
	private String receivers;	//短信发送者
	
	
	@Autowired
	O2OMessageDao o2OMessageDao;
	
	private String convertEmailContent() {
		//先去数据库中统计数据
		String sql = "select CASE message_type WHEN 'FK' THEN '放款当日'"+
							" WHEN 'FX2' THEN '付息日前两天' "+
							" WHEN 'DK15' THEN '贷款到期日前15天' "+
							" WHEN 'DK2' THEN '贷款到期日前2天' "+
							" WHEN 'YQ2' THEN '逾期的第二天' "+
							"  ELSE '其它' END, "+
							"  CASE status WHEN '0' THEN '未插入短信表' "+
							"  WHEN '1' THEN '已插入短信表' "+
							"  ELSE '其它' END, "+
							"  CASE platform_type WHEN 'OLD' THEN '老系统平台' "+
							"  WHEN 'NEW' THEN '新系统平台' "+
							"  ELSE '其它' END, "+
							"  count(*)  from o2o_message l where DATE_FORMAT(adddate(curdate(), '-1 days'), '%Y-%m-%d')  = DATE_FORMAT(create_time, '%Y-%m-%d') "
							+ " GROUP BY l.message_type,l.status,l.platform_type " ;
		List<Object[]> list = o2OMessageDao.findParams(sql);
		if(list.size()>0){
			ViewContext.put("o2oMessageeMail", list);
		}else{//如果是没有统计数据
			Object []a = {"没有数据","没有数据","没有数据","没有数据"};
			list.add(a);
			ViewContext.put("o2oMessageeMail", list);
		}
		String html = HtmlRestResult.buildHtmlFromTemplate("/messageTemplate/messageEmailTemplate");
		return html;
	}

}